<?php
class User extends MY_Controller{
	//获取token
	function update_user_info(){
		$data = $this->user_post_data;
		$user_id = $data['user_token']['user_id'];
		unset($data['user_token']);
		if(!empty($data['head_img_url'])){
			$data['head_img_url'] = get_qiniu_url($data['head_img_url']);
		}
		$this->db->update("users", $data, array("id" => $user_id));
		if($this->db->affected_rows() > 0){
			echo json_encode(array("code" => 1, "msg" => '资料修改成功'));
		}else{
			echo json_encode(array("code" => 0, "user" => '资料修改失败，请重试'));
		}
	}

	function dynamic_list(){
		$data = $this->user_post_data;
		$limit = !empty($data['limit']) ? $data['limit'] : 0;
		$this->load->model("Users");
		$this->offset = 10;
		$dynamic_list = $this->Users->get_dynamic_list($limit * $this->offset, $this->offset);
		if(!empty($dynamic_list['count'])){
			foreach ($dynamic_list['list'] as $key => $value) {
				if(empty($value['head_img_url'])){
					if($value['gender'] == 1){
						$dynamic_list['list'][$key]['head_img_url']	= get_qiniu_url('FtE8Gn7PqWv0W7aVTuab8RcuGxlm');
					}else{
						$dynamic_list['list'][$key]['head_img_url'] = get_qiniu_url('Fsof6z54HyIM401i0amzqo3VzrF3');
					}
				}
				$text = "坚持 #{$value['name']}# " . "第{$value['day']}天<br>";
				$dynamic_list['list'][$key]['text'] = $text . $dynamic_list['list'][$key]['text'];
			}
		}
		$dynamic_list['total_page'] = ceil($dynamic_list['count'] / $this->offset);
        echo json_encode(array("code" => 1, "data" => $dynamic_list));
	}
}